Skip to content

fix(lint-mdx): handle multi-line <img> tags in alt-attribute check - #1793

Open
teyrebaz33 wants to merge 1 commit into
base:masterfrom
teyrebaz33:fix/lint-mdx-multiline-img-alt-false-positive
Open

fix(lint-mdx): handle multi-line <img> tags in alt-attribute check#1793
teyrebaz33 wants to merge 1 commit into
base:masterfrom
teyrebaz33:fix/lint-mdx-multiline-img-alt-false-positive

Conversation

@teyrebaz33

Copy link
Copy Markdown

Fixes #1792

Problem

The alt-attribute check in scripts/lint-mdx.js only looked at the single line containing <img, so when an tag's attributes were spread across multiple lines, a present alt= attribute on a later line was never seen, producing a false-positive warning.

Fix

The check now accumulates lines starting at the tag until the tag closes (or end of file) before checking for alt=, matching the multi-line lookback pattern already used by the adjacent Frame-wrapping check in the same function.

Verification

  • node scripts/lint-mdx.js all: warnings drop from 75 to 70 (exactly the 5 false positives fixed), errors unchanged at 1246
  • Tested against a synthetic multi-line with no alt: still correctly flagged
  • Tested against a synthetic multi-line with alt= on a later line: no longer flagged

The alt-attribute check in checkMintlifyComponents only looked at the
single line containing '<img', so when an <img> tag's attributes were
spread across multiple lines (a common JSX formatting style used
throughout docs/), a present alt= attribute on a later line was never
seen and the linter reported a false-positive missing-alt warning.

This affected 5 warnings across 3 files that already had a valid
alt attribute:
- docs/base-account/improve-ux/sponsor-gas/paymasters.mdx (2)
- docs/base-account/reference/ui-elements/brand-guidelines.mdx (2)
- docs/snippets/BasePayButton.mdx (1)

The check now accumulates lines starting at the <img> tag until the
tag closes (or end of file), matching the multi-line lookback pattern
already used by the adjacent <Frame>-wrapping check in the same file.

Verified with node scripts/lint-mdx.js all: warnings drop from 75 to
70 (exactly the 5 false positives), errors unchanged at 1246. Also
verified against a synthetic missing-alt case and a synthetic
multi-line-with-alt case to confirm the check still catches real
violations and doesn't over-suppress.
@cb-heimdall

Copy link
Copy Markdown
Collaborator

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 0
Sum 1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

lint-mdx.js: false-positive missing-alt warning for multi-line <img> tags

2 participants